package com.tools.common.thread;

import com.tools.common.object.Note;

import java.util.Objects;

/**
 * 时间值和它的单位的包装类
 * */
@Note("时间值和它的单位的包装类")
public final class TimePair {

    @Note("源时间值")
    private final long sourceTime;

    @Note("源时间单位")
    private final Timeunit sourceTimeunit;


    public TimePair(long sourceTime, Timeunit sourceTimeunit) {
        if(sourceTimeunit == null) throw new IllegalArgumentException("源时间单位不能为 null");
        this.sourceTime = sourceTime;
        this.sourceTimeunit = sourceTimeunit;
    }

    public long getSourceTime() {
        return sourceTime;
    }

    public Timeunit getSourceTimeunit() {
        return sourceTimeunit;
    }

    public long toNano() {
        return Timeunit.toNano(sourceTime, sourceTimeunit);
    }

    public long toMicro() {
        return Timeunit.toMicro(sourceTime, sourceTimeunit);
    }

    public long toSecond() {
        return Timeunit.toSecond(sourceTime, sourceTimeunit);
    }

    public long toMini() {
        return Timeunit.toMini(sourceTime, sourceTimeunit);
    }

    public long toHour() {
        return Timeunit.toHour(sourceTime, sourceTimeunit);
    }

    public long toDay() {
        return Timeunit.toDay(sourceTime, sourceTimeunit);
    }

    public long toWeek() {
        return Timeunit.toWeek(sourceTime, sourceTimeunit);
    }

    public long to28DayMonth() {
        return Timeunit.to28DayMonth(sourceTime, sourceTimeunit);
    }

    public long to29DayMonth() {
        return Timeunit.to29DayMonth(sourceTime, sourceTimeunit);
    }

    public long to30DayMonth() {
        return Timeunit.to30DayMonth(sourceTime, sourceTimeunit);
    }

    public long to31DayMonth() {
        return Timeunit.to31DayMonth(sourceTime, sourceTimeunit);
    }

    public long to365DayYear() {
        return Timeunit.to365DayYear(sourceTime, sourceTimeunit);
    }

    public long to366DayYear() {
        return Timeunit.to366DayYear(sourceTime, sourceTimeunit);
    }

    public String toText() {
        return sourceTime + " " + sourceTimeunit.getText();
    }

    @Override
    public String toString() {
        return "TimePair{" + sourceTime + ' ' + sourceTimeunit + '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TimePair timePair = (TimePair) o;
        return sourceTime == timePair.sourceTime && sourceTimeunit == timePair.sourceTimeunit;
    }

    @Override
    public int hashCode() {
        return Objects.hash(sourceTime, sourceTimeunit);
    }
}
